<?php
function strMax($str, $maxWidth, $encoding='utf-8'){
		    $strlen = mb_strlen($str);
		if($strlen > $maxWidth){
		    $newStr = '';
		    for($pos = 0, $currwidth = 0; $pos < $strlen; ++$pos ){
		        $ch = mb_substr($str, $pos, 1, $encoding);
		        if ($currwidth + mb_strwidth($ch, $encoding) > $maxWidth)
		            break;

		        $newStr .= $ch;
		        $currwidth += mb_strwidth($ch, $encoding) > 1 ? 2 : 1;
		    }
			$newStr = $newStr."...";
			if($newStr == "..."){
				$newStr = "";
			}
		}else{
			$newStr = $str;
		}
		    return $newStr;
}
?>